<?php

/**
 * index actions.
 *
 * @package    pikusa
 * @subpackage index
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class indexActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
  	#$uploadToDirBase = "C:\AppServ\www\pikuza\web\p";
  	$uploadToDirBase = "/home/meteenee/domains/meteenee.com/public_html/pikun/p";
  	$originalPath = $uploadToDirBase."/o";
  	
  	
  	
  	
  	
  	
  	$c = new Criteria();
  	$c->add(PhotoPeer::NAME, $request->getGetParameter('p', NULL));
  	$photo = PhotoPeer::doSelectOne($c);
  	
  	if(count($photo)){
  		
  		$imagePath = $originalPath."/".$photo->getName();
  		$size = getimagesize($imagePath);
	  	
  		$ImageWidth = $size[0];
  		$ImageHeight = $size[1];
  		$TypeCode = $size[2];
  		$desc = $size[3];
  		$bits = $size['bits'];
  		$channels = $size['channels'];
  		$mime = $size['mime'];
  		
  		
		$ImageType=($TypeCode==1?"gif":($TypeCode==2?"jpeg":
	             ($TypeCode==3?"png":FALSE)));
	    
		$CreateFunction="imagecreatefrom".$ImageType;
		$OutputFunction="image".$ImageType;
		
		
  		header('Content-Type: '.$mime);
  		
  		$source = $CreateFunction($imagePath);
  		$OutputFunction($source);
  		
  		exit();
  		
  	}else{
  		$this->redirect('/index.php');
  	}
  	
    //
	return sfView::NONE;
  }
}
